package com.bmf.module.testQuestions.controller;

import com.bmf.core.result.PageResponse;
import com.bmf.file.utils.UploadFileUtil;
import com.bmf.module.testQuestions.service.SmallQuestionService;
import com.bmf.module.testQuestions.vo.QuestionCreateVo;
import com.bmf.module.testQuestions.vo.QuestionPageVo;
import com.bmf.module.testQuestions.vo.QuestionResultVo;
import com.bmf.module.testQuestions.vo.QuestionUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.bmf.core.result.R;
import org.springframework.web.multipart.MultipartFile;

/**
 * (SmallQuestion)表控制层
 *
 * @author makejava
 * @since 2022-11-29 18:14:01
 */
@RestController
@RequestMapping("smallQuestion")
@Api(tags = {"试题接口"})
public class SmallQuestionController{
    /**
     * 服务对象
     */
    @Autowired
    private SmallQuestionService smallQuestionService;

    /**
     * 分页查询试题
     *
     * @return 所有数据
     */
    @PostMapping("/selectPage")
    @ApiOperation(value = "分页查询试题")
    public R<PageResponse<QuestionResultVo>> selectPage(@RequestBody QuestionPageVo questionPageVo) {
        return R.success(smallQuestionService.selectPage(questionPageVo));
    }

    /**
     * 通过主键查询单条试题
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "通过主键查询单条试题")
    public R<QuestionResultVo> selectOne(@PathVariable Integer id) {
        return R.success(smallQuestionService.selectOne(id));
    }

    /**
     * 新增试题
     *
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "新增试题")
    public R<Integer> insert(@RequestBody QuestionCreateVo questionCreateVo) {
        return R.success(smallQuestionService.insert(questionCreateVo));
    }

    /**
     * 修改试题
     *
     * @param questionUpdateVo 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation(value = "修改试题")
    public R<Void> update(@RequestBody QuestionUpdateVo questionUpdateVo) {
        smallQuestionService.update(questionUpdateVo);
        return R.ok();
    }

    /**
     * 删除试题
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation(value = "删除试题")
    public R<Void> delete(@RequestBody List<Integer> ids) {
        smallQuestionService.delete(ids);
        return R.ok();
    }

    @ApiOperation(value = "上传", notes = "上传", httpMethod = "POST")
    @PostMapping("/upload")
    public R<String> upload( MultipartFile file){
        return R.success(UploadFileUtil.tempUploadFile(file,null));
    }



}

